import { defineComponent, reactive, ref } from "vue";
import Page from "@/components/public/page/page";
import { CardWithTitle } from "@/components/public/card/card";
import LTable from "@/components/public/lTable/lTable";
import userService from "@/modules/user/user.service";
import styles from "./userPage.module.less";
export default defineComponent({
  name: "settlementOfClaim",
  setup() {
    const state = reactive({
      toolbar: {
        left: ["refresh"],
        right: ["filter"],
      },
      dataSource: [],
      columns: [
        {
          title: "ID",
          dataIndex: "id",
          align: "center",
          width: "100px",
        },
        {
          title: "姓名",
          dataIndex: "name",
          align: "center",
          width: "200px",
        },
        {
          title: "头像",
          dataIndex: "avatar",
          align: "center",
          width: "200px",
        },
        {
          title: "手机号",
          dataIndex: "mobile",
          align: "center",
          width: "180px",
        },
        {
          title: "创建时间",
          dataIndex: "create_time",
          align: "center",
          width: "220px",
        },
      ],
      loading: false,
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10,
      },
    } as any);
    // 服务
    const $service = new userService();
    // 表格节点
    const LTableRef = ref(null as any);
    // 表格状态变更
    const tableChangeHandler = (pag: { pageSize: number; current: number }) => {
      state.pagination.current = pag.current;
      state.pagination.pageSize = pag.pageSize;
    };
    return () => (
      <Page>
        <CardWithTitle title="用户列表">
          <LTable
            ref={LTableRef}
            service={$service}
            toolbar={state.toolbar}
            v-model={state}
          >
            <a-table
              bordered={true}
              scroll={{ x: "max-content" }}
              dataSource={state.dataSource}
              columns={state.columns}
              loading={state.loading}
              pagination={state.pagination}
              onChange={tableChangeHandler}
              rowKey="id"
              v-slots={{
                bodyCell: ({ column, record }: any) => {
                  // 头像
                  if (column.dataIndex === "avatar") {
                    return (
                      <img class={styles.avatar} src={record.avatar} />
                    );
                  }
                },
              }}
            />
          </LTable>
        </CardWithTitle>
      </Page>
    );
  },
});